const Preload = require('./preload');
// 创建云
class Clouds  {
  constructor(keys) {
    this.cloudSpeed = 0.1;
    this.players = game.add.group();
    let role1=this.players.create(0,0,keys);
    this.role1W=role1.width;
    let role2=this.players.create(this.role1W,0,keys);
  }
  addPlayer() {
    game.add.tween(this.players).to({x:-this.role1W},this.role1W/this.cloudSpeed).start().loop()
  }
  addPlayer2(bh){
    this.players.y=bh-this.players.height;
    this.players.x=-this.role1W;
    game.add.tween(this.players).to({x:0},this.role1W/this.cloudSpeed).start().loop();
  }
}
class Start extends Preload {
  constructor() {
    super();
    this.cloudSpeed = 12000;
    this.clouds1 = {};
    this.clouds2 = {};
  }
  addClouds(keys) {
    this.clouds1 = new Clouds("cloud_top");
    this.clouds1.addPlayer();
    this.clouds2=new Clouds("cloud_bottom");
    this.clouds2.addPlayer2(this.bh);
  }
  setBg() {
    let bg = game.add.image(0, 0, "bg_preload")
    bg.width = this.bw;
    bg.height = this.bh;
    this.addClouds();
    let bg2 = game.add.image(0, 0, "bg_preload1");
    this.scales(bg2, 0.5);
  }
  setBtn() {
    let btny = this.bh - this.setY(180 / 2);
    console.log(btny);
    let btn = game.add.image(this.cx, btny, "btn_start");
    btn.anchor.setTo(0.5, 0);
    btn.inputEnabled=true;
    btn.events.onInputDown.add(v => {
      game.state.start('Ready');
    })
  }
  create() {

    document.querySelector(".preDog").style.display = "none";
    this.setBg();
    this.setBtn();
    // game.input.onDown.add(this.mouseDragStart, this);
  }
  mouseDragStart() {
    // console.log(1);
  }

  update() {

  }
}
module.exports = Start;